@import '../variables.css';

:root {
  --checkbox-size: 12px;
}

.checkbox {
  display: flex;
  flex-direction: column;
  position: relative;
  color: var(--color-text);
  line-height: var(--line-height);
  margin-bottom: 0;

  &.fullWidth {
    width: 100%;
  }
}

/**
 * Label
 */
.label {
  margin-bottom: 0;
}

/**
 * Custom checkbox styling
 */
.checkboxIcon {
  position: relative;
  width: var(--checkbox-size);
  height: var(--checkbox-size);
  border: 1px solid var(--color-border-form);
  border-radius: 25%;
  background: var(--color-fill-form-element);
  display: flex;
  overflow: hidden;
  flex-shrink: 0;

  & svg {
    opacity: 0;
  }
}

.inner {
  min-height: var(--control-min-size-desktop);
  display: flex;
  align-items: baseline;
  cursor: pointer;
  flex-grow: 2;
  position: relative;
  border-radius: var(--radius);
  font-size: var(--font-size-medium);
}

/**
 * Label text
 */
.labelText {
  margin: 0 0 0 var(--gutter-static-one-third);
  display: flex;
  align-items: center;
  min-height: var(--control-min-size-desktop);
}

[dir="rtl"] .labelText {
  margin: 0 var(--gutter-static-one-third) 0 0;
}

/**
 * Input
 */
.input {
  position: absolute;
  z-index: 10;
  opacity: 0;
  cursor: pointer;
}

.noLabel .input {
  transform: scale(1.9);
}

/**
 * Vertical label alignment
 */
.vertical .label {
  flex-direction: column;
  align-items: flex-start;

  & .labelText {
    margin: 0 0 var(--control-label-margin-bottom) 0;
    min-height: 0;
  }

  & .inner {
    align-items: center;
  }
}

/**
 * Inline checkbox
 */
.inline {
  display: inline-flex;

  &.noLabel .inner {
    align-items: center;
  }
}

/* Apply spacing between inline checkboxes when stacked */
.inline + .inline {
  margin-left: var(--gutter-static-two-thirds);
  margin-right: 0;
}

[dir="rtl"] .inline + .inline {
  margin-right: var(--gutter-static-two-thirds);
  margin-left: 0;
}

/**
 * Checkbox feedback
 */
.checkboxFeedback {
  font-size: var(--font-size-medium);
}

.hasWarning {
  & .checkboxFeedback {
    color: var(--warn);
  }

  & .checkboxIcon {
    border-color: var(--warn);
  }
}

.hasError {
  & .checkboxFeedback {
    color: var(--error);
  }

  & .checkboxIcon {
    border-color: var(--error);
  }
}

/**
 * Interaction styles (hover, focus, active)
 */
.checkboxInteractionStylesControl {
  composes: interactionStylesControl from "../sharedStyles/interactionStyles.css";
}

.checkboxInteractionStyles {
  composes: interactionStyles boxOffsetStartSmall boxOffsetEndSmall from "../sharedStyles/interactionStyles.css";
}

.labelFocused {
  composes: isFocused from "../sharedStyles/interactionStyles.css";
}

/**
 * Disabled
 */
.disabled {
  & .checkboxIcon {
    opacity: 0.5;
  }

  &:hover .inner {
    cursor: default;
  }
}

/**
 * Checked state
 */

.input:checked + .checkboxIcon {
  background-color: #000;

  & svg {
    opacity: 1;
  }

  & svg path {
    stroke: #fff;
  }
}
